﻿using DimsMapper.Modules;

namespace DimsMapper.Proto
{
    class Scenery : CommonExt
    {
        Proto.SceneryTypes type;

        Prototypes.SceneryProtoCommonData commonData;
        Prototypes.SceneryProtoData sceneryData;

        public Scenery(DBFile file)
        {
            LoadData(file);
        }

        protected override void LoadData(DBFile file)
        {
            base.LoadData(file);

            sceneryData = new Prototypes.SceneryProtoData();

            type = (Proto.SceneryTypes)file.ReadInt();

            sceneryData.Material = file.ReadInt();
            sceneryData.SoundID = file.ReadByte();

            switch (type)
            {
                case Proto.SceneryTypes.Door:
                    Prototypes.SceneryProtoDoorData door = new Prototypes.SceneryProtoDoorData();
                    door.OpenFlags = file.ReadInt();
                    door.KeyCode = file.ReadInt();
                    commonData = door;
                    break;

                case Proto.SceneryTypes.Stairs:
                    Prototypes.SceneryProtoStairsData stairs = new Prototypes.SceneryProtoStairsData();
                    stairs.ElavationTile = file.ReadInt();
                    stairs.DestMapId = file.ReadInt();
                    commonData = stairs;
                    break;

                case Proto.SceneryTypes.Elevator:
                    Prototypes.SceneryProtoElevatorData elevator = new Prototypes.SceneryProtoElevatorData();
                    elevator.ElevatorTypeID = file.ReadInt();
                    elevator.ElevatorLevel = file.ReadInt();
                    commonData = elevator;
                    break;

                case Proto.SceneryTypes.LadderUp:
                case Proto.SceneryTypes.LadderDown:
                    Prototypes.SceneryProtoLadderData ladder = new Prototypes.SceneryProtoLadderData();
                    ladder.EelevationAndTile = file.ReadInt();
                    commonData = ladder;
                    break;

                case Proto.SceneryTypes.Generic:
                    Prototypes.SceneryProtoGenericData generic = new Prototypes.SceneryProtoGenericData();
                    generic.Unknown = file.ReadInt();
                    commonData = generic;
                    break;

                default:

                    break;
            }
        }

        public Proto.SceneryTypes Type
        {
            get { return type; }
        }

        public Prototypes.SceneryProtoDoorData door
        {
            get { return (Prototypes.SceneryProtoDoorData)commonData; }
        }

        public Prototypes.SceneryProtoStairsData stairs
        {
            get { return (Prototypes.SceneryProtoStairsData)commonData; }
        }

        public Prototypes.SceneryProtoElevatorData elevator
        {
            get { return (Prototypes.SceneryProtoElevatorData)commonData; }
        }

        public Prototypes.SceneryProtoLadderData ladder
        {
            get { return (Prototypes.SceneryProtoLadderData)commonData; }
        }

        public Prototypes.SceneryProtoGenericData generic
        {
            get { return (Prototypes.SceneryProtoGenericData)commonData; }
        }
    }
}
